#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File  :price_warning_page.py
# Time  :2025/3/26 17:48
# Email :fortunatedong@163.com
# Author:by Adonli
import os

import streamlit as st
import pandas as pd
import numpy as np
from config import ROOT_DIR
from config import Header_space
Header_space()
jingdong_sell_price_file = os.path.join(ROOT_DIR, 'Datas', 'jingdong_sell_price.csv')
st.subheader("国铁价格预警", divider=True)
def tab_1():

    df = pd.read_csv(jingdong_sell_price_file, index_col=False, dtype=str, keep_default_na=False)

    columns = {
        "guotie_sku": "国铁SKU",
        "sku_name": "商品名称",
        "guotie_price": "国铁价格",
        "jd_url": "京东URL",
        "jingdong_sell_price": "京东价格",
        "contrast":"比价结果",
    }
    # print(df)
    df.rename(columns=columns,inplace=True)
    config = {
        '国铁SKU': st.column_config.TextColumn(),
        '商品名称': st.column_config.TextColumn(width="medium"),
        '国铁价格': st.column_config.TextColumn(),
        '京东URL': st.column_config.LinkColumn(),
        '京东价格': st.column_config.TextColumn(),
        '比价结果': st.column_config.TextColumn(),

    }
    def color_red(s):
        color = 'red' if s == "异常" else 'black'
        return 'color: %s' % color
    df_sorted = df.sort_values(by='比价结果', ascending=True)
    st.dataframe(df_sorted.style.applymap(color_red,subset=['比价结果']),width=1600, column_config=config,key="warning_table")

tab_1()


